var table =null;
var orderStatusa = null;
layui.use(['table','form'], function(){
    table = layui.table;
    var form = layui.form;

    //第一个实例
    table.render({
        elem: '#demo'
        ,height: 312
        ,url: '/order/intermediate/getCurr' //数据接口
        ,page: {
                layout: ['count', 'prev', 'page', 'next', 'limit'],//展示按钮 以及按钮的顺序
                groups: 5,
                limit: 5,// 每条的页数
                limits: [5, 10, 20] // 可选的每条的页数
            }
        ,id:"courseOrder"
        ,cols: [[ //表头
            {field: '', title: '', type: 'checkbox'},
            {field: 'orderId', title: '序号'}
            ,{field: 'orderReference', title: '订单编号'}
            ,{field: 'userName', title: '用户昵称'}
            ,{field: 'curriculumName', title: '课程名称'}
            ,{field: 'orderSource', title: '订单来源',templet: function(row){
                    if(row.orderSource == '2'){
                        return "小程序";
                    }if(row.orderSource == '3'){
                        return"APP";
                    }
                }}
            ,{field: 'orderStatus', title: '订单状态',sort: true,templet: function(row) {
                    if (row.orderStatus == '2') {
                        return "待付款";
                    }if (row.orderStatus == '3') {
                        return "已付款";
                    }if (row.orderStatus == '4') {
                        return "待发货";
                    }if (row.orderStatus == '5') {
                        return "已发货";
                    }if (row.orderStatus == '6') {
                        return "已签收";
                    }if (row.orderStatus == '7') {
                        return "退货申请";
                    }if (row.orderStatus == '8') {
                        return "退货中";
                    }if (row.orderStatus == '9') {
                        return "已退货";
                    }if (row.orderStatus == '10') {
                        return "取消交易";
                    }if (row.orderStatus == '11') {
                        return "拒绝退货";
                    }if (row.orderStatus == '12') {
                        return "待评论";
                    }if (row.orderStatus == '13') {
                        return "已完成";
                    }
                }}
            ,{field: 'orderPayment', title: '支付方式',templet: function(row){
                    if(row.orderPayment == '1'){
                        return "微信支付";
                    }if(row.orderPayment == '2'){
                        return"余额支付";
                    }if(row.orderPayment == '3'){
                        return"支付宝支付";
                    }if(row.orderPayment == '4'){
                        return"未支付";
                    }
                }}
            ,{field: 'currculumCreatedBy', title: '主要讲师'}
            ,{title: '操作', toolbar: '#tooldemo'}
        ]],
        parseData: function (res) {
            return {
                "code": res.code,
                "msg": res.msg,
                "count": res.count,
                "data": res.data
            }
        },toolbar: '#toolbarbtn'
    });
    table.on('tool(userdemo)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）

        if(layEvent === 'ck'){ //查看
            localStorage.setItem("orderId",data.orderId)
            $.ajax({
                type:"post",
                url:"/order/intermediate/viewCourses",
                data:{"orderId":data.orderId},
                success:function (res){
                    layer.open({
                        type: 2,
                        content: 'viewcourses.html',
                        area: ['80%', '80%'],
                        success:function (layero,index){
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象，执行iframe页的方法：
                            iframeWin.aaa(res);//调用子页面的方法，得到子页面返回的ids
                        }

                    })
                }
            })
        }
    });
    form.on('submit(go)', function(data){
        console.log(data.field)
        table.reload('courseOrder', {

            where: {
                orderStatus:orderStatusa,
                orderPayment:data.field.orderPayment,
                orderSource:data.field.orderSource,
                orderStatus:data.field.orderStatus

            }

        });

    });

});
function squery(d) {
    console.log(d)
    orderStatusa = d;
    table.reload('courseOrder', {
        where:{
            "orderStatus":d
        }
    });
}